<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<script type="text/javascript">
    function page(n, s) {
        $("#pageNo").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }
    $(function () {
        $("#copiedBtn").on('click', function () {
            var ordersStatus = '2';
            updateStatus(ordersStatus);
        })
        //转抄停止
        $("#copiedStopBtn").on('click', function () {
            var ordersStatus = '4';
            updateStatus(ordersStatus);
        })
        //修改医嘱状态
        function updateStatus(ordersStatus) {
            var ordersIds = getSelectOrderIds(ordersStatus);//以逗号分隔
            if (ordersIds.length > 1) {
                return delLoad("nurseIndexDiv", '${ctx}/orders/orders/delete?id=' + ordersIds + "&orderStatus=" + ordersStatus, '${ctx}/orders/orders/findNurseOrders?pageFlag=0');
            }
        }


        /**
        *  ordersStatus 1 :传输医嘱只能传输新建医嘱
        * @param ordersStatus
        * @returns {string}
         */
        function getSelectOrderIds(ordersStatus) {
            var parentOrders = $("#contentTable input[name=ordersId]:checked");
            if (parentOrders.length == 0) {
                toastr.error("请先选择一条医嘱！");
                return "";
            }
            var ordersId = "";
            parentOrders.each(function () {
              var status=$(this).val().split(',')[1];
              if(ordersStatus=='4'&&status!='8'){
                  toastr.error("请选择医生停止的状态医嘱！");
                  return "";
              };
              if(ordersStatus=='2'&&status=='8'){
                    toastr.error("请选择不是医生停止的状态医嘱！");
                    return "";
              };
              ordersId = ordersId + $(this).val().split(',')[0]+ ",";
            })
            ordersId = ordersId.substring(0, ordersId.length - 1);
            return ordersId;
        }

        //全选事件
        $("#all").on('click', function () {
            var isChecked = $(this).prop("checked");
            $("input[name='ordersId']").prop("checked", isChecked);
        })
        $("#contentTable").treeTable({expandLevel:10});
    })


    function doctoradviseprint() {
        var visitId = $("#visitId").val();
        var patientId = $("#patientId").val();
        var startDate = $("#startDate").val();
        var endDate = $("#enddate").val();
        var repeatIncaditor = $("#repeatIncaditor").val();
        printPdf('${ctx}/orders/orders/doctoradviseprint', 'patientId=' + patientId+'&visitId='+visitId+'&createDate='+startDate+'&endDate='+endDate+'&repeatIncaditor='+repeatIncaditor);
    }
 </script>
<div class="app">
    <section class="layout">
        <section class="main-content col-lg-12" id="LeftDiv">
            <div class="content-wrap">
                <div class="wrapper" style="bottom: 50px;">
                     <ul class="nav nav-tabs">
                        <li><a href="#" onclick="loadDiv('mainCenterDiv','${ctx}/nurse/index')">床位列表</a></li>
                        <li class="active"><a href="#" onclick="loadDiv('nurseIndexDiv','${ctx}/orders/orders/findNurseOrders?pageFlag=0')">医嘱转抄</a></li>
                     </ul>
                    <section class="panel panel-default">
                        <div class="panel-body">
                             <div class="table-responsive no-border">
                                <div class="datatable-top">
                                    <div class="pull-left">
                                        <form:form id="searchForm" modelAttribute="orders"
                                                   onsubmit="return loadDivForm('nurseIndexDiv','searchForm','${ctx}/orders/orders/findNurseOrders');"
                                                   method="post" class="form-inline">
                                            <form:hidden path="patientId" id="patientId"/>
                                            <form:hidden path="visitId" id="visitId"/>
                                            <form:hidden path="pageFlag" value="0"/>
                                            <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
                                            <input id="pageSize" name="pageSize" type="hidden"  value="${page.pageSize}"/>
                                            <form:select path="repeatIncaditor" id="repeatIncaditor" itemLabel="label" itemValue="value"
                                                         class="form-control" data-parsley-required="true">
                                                <form:option value="" label="全部"/>
                                                <form:option value="0" label="临时"/>
                                                <form:option value="1" label="长期"/>
                                            </form:select>
                                             <input name="startTime" id="startDate" value="${orders.startTime}" class="form-control Wdate" type="text"
                                                   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                                   readonly="readonly" style="margin-left:40px;"/>
                                            <label>至：</label>
                                            <input name="endTime"  id="enddate" value="${orders.endTime}" class="form-control Wdate" type="text"
                                                   readonly="readonly"
                                                   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
                                            <input name="date" id="week" class="btn btn-default" type="button" value="一周内" onclick="dateCondition('week',-7,'startDate')"/>
                                            <input name="date" id="halfMonth" class="btn btn-default" type="button" value="半月内" onclick="dateCondition('halfMonth',-15,'startDate')"/>
                                            <input name="date"  id="month" class="btn btn-default" type="button" value="一个月内" onclick="dateCondition('month',-30,'startDate')"/>
                                            <input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
                                            <input id="copiedBtn" class="btn btn-primary" type="button" value="转抄"/>
                                            <input id="copiedStopBtn" class="btn btn-primary" type="button" value="转抄停止"/>
                                            <input id="print" class="btn btn-primary" type="button" onclick="doctoradviseprint()" value="打印"/>
                                         </form:form>
                                    </div>
                                </div>
                                <table id="contentTable" class="table table-bordered mg-t datatable" checkbox="true">
                                    <thead>
                                    <tr>
                                        <th><input type=checkbox id="all"></th>
                                        <th>下达时间</th>
                                        <th>医嘱内容</th>
                                        <th>类别</th>
                                        <th>长期-来源</th>
                                        <th>医嘱状态</th>
                                        <th>途径</th>
                                        <th>频次</th>
                                        <th>执行时间</th>
                                        <th>单次用量</th>
                                        <th>规格</th>
                                        <th>药品厂商</th>
                                        <th>开单医生</th>
                                        <th>医生说明</th>
                                        <th>执行科室</th>
                                        <th>床号</th>
                                        <th>姓名</th>
                                        <th>医生停止时间</th>
                                     </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${page.list}" var="orders" varStatus="ss">
                                        <tr id="${orders.id}" style="text-align: center;">
                                            <td><input type=checkbox name="ordersId" value="${orders.id},${orders.orderStatus}"></td>
                                            <td><fmt:formatDate value="${orders.createDate}"  pattern="MM-dd HH:mm"/></td>
                                            <td> ${orders.orderText}</td>
                                            <td> ${orders.isDrugTran}</td>
                                            <td> ${orders.repeatIncaditorTran}-${orders.isApplyTran}</td>
                                            <td> ${orders.orderStatusTran}</td>
                                            <td> ${fns:getSysDictLabel(orders.administration, 'ADMINISTRATION_DICT', '')}</td>
                                            <td> ${orders.freqDesc}</td>
                                            <td> ${orders.nursePerformTime}</td>
                                            <td>
                                                <c:if test="${orders.isDrugTran=='药品'}">
                                                    ${orders.singleDose}( ${orders.doseUnits})
                                                </c:if>
                                            </td>
                                            <td> ${orders.drugSpec}</td>
                                            <td> ${orders.firmId}</td>
                                            <td> ${fns:getUserName(orders.createBy.id)}</td>
                                            <td> ${orders.doctInstruction}</td>
                                            <td> ${fns:getDeptName(orders.performedBy,"")}</td>
                                            <td> ${orders.bedNo}</td>
                                            <td> ${orders.name}</td>
                                            <td><fmt:formatDate value="${orders.stopInDate}"  pattern="MM-dd HH:mm"/></td>
                                          </tr>
                                        <c:if test="${orders.children.size()>0}">
                                            <c:forEach items="${orders.children}" var="child" varStatus="ss">
                                                <tr id='${ss.count}' pId='${orders.id}'>
                                                   <td></td>
                                                    <td><fmt:formatDate value="${child.createDate}"  pattern="MM-dd HH:mm"/></td>
                                                    <td> ${child.orderText}</td>
                                                    <td> ${child.isDrugTran}</td>
                                                    <td> ${child.repeatIncaditorTran}-${child.isApplyTran}</td>
                                                    <td> ${child.orderStatusTran}</td>
                                                    <td> ${fns:getSysDictLabel(orders.administration, 'ADMINISTRATION_DICT', '')}</td>
                                                    <td> ${orders.freqDesc}</td>
                                                    <td> ${child.nursePerformTime}</td>
                                                    <td>
                                                        <c:if test="${child.isDrugTran=='药品'}">
                                                            ${child.singleDose}( ${child.doseUnits})
                                                        </c:if>
                                                    </td>
                                                    <td> ${child.drugSpec}</td>
                                                    <td> ${child.firmId}</td>
                                                    <td> ${fns:getUserName(child.createBy.id)}</td>
                                                    <td> ${child.doctInstruction}</td>
                                                    <td> ${fns:getDeptName(child.performedBy,"")}</td>
                                                    <td> ${child.bedNo}</td>
                                                    <td> ${child.name}</td>
                                                    <td><fmt:formatDate value="${child.stopInDate}"  pattern="MM-dd HH:mm"/></td>
                                                  </tr>
                                            </c:forEach>
                                        </c:if>
                                    </c:forEach>
                                    </tbody>
                                </table>
                                <div class="pagination">${page}</div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </section>
    </section>

</div>

